<template>
	<!--我的待开赛-->
	<scroll-view class="page-content" :scroll-top="scrollTop" scroll-y="true" @scrolltolower="loadmore()">
		<view class="page-body">
			<template v-if="datalist && datalist.length > 0 ">
				<block v-for="(item,index) in datalist" :key="index">
					<view class="record_li" @click="todetail(item.id)">
						<view class="record_top">
							<view class="record_t">{{item.game_start_time}}</view>
							<view class="icon-gd icons icon-gengduo"></view>
						</view>
						<view class="record_txt">赛事名：{{item.title}}</view>
						<view class="record_txt">团队名称：{{item.team_name}}</view>
						<view class="record_txt">用时时长：<text class="record_text">{{item.game_time}}</text></view>
					</view>
				</block>
				<!-- 上拉加载 -->
				<view class="det-con-more">
					<load-more :loadmore="load_more1"></load-more>
				</view>
			</template>
			<!--无数据-->
			<empty v-else no-full type="noData"></empty>
		</view>
	</scroll-view>
</template>

<script>
	import {
		mapMutations,
		mapState
	} from 'vuex'
	import uniSwiperDot from "@/components/uni-swiper-dot/uni-swiper-dot.vue"
	import raceList from "@/pages/index/components/race_list.vue"
	import companyList from "@/pages/index/components/company_list.vue"
	import loadMore from '@/components/uni-load-more/load-more.vue'
	import {
		getgamelists,
		getuserawaitlists, //获取待开赛比赛列表【我的】
		getGameOverLists
	} from '@/common/api.js'
	export default {
		components: {
			uniSwiperDot,
			raceList,
			companyList,
			loadMore
		},
		data() {
			return {
				scrollTop: 0,
				noData: false,
				load_more1: '', //下拉加载文字
				load_sta: false, //是否是加载状态
				datalist: [],
				formData: {
					page: 1,
					limit: 10,
				},
				datalist:[]
			}
		},
		computed: {
			...mapState(['hasLogin', 'openid'])
		},
		onShow() {
			this.getdata(this.formData);
		},
		methods: {
			//下拉加载
			loadmore() {
				console.log('下拉加载');
				let _self = this;
				_self.load_sta = true;
				if (_self.active === 1) {
					_self.formData.page++;
					_self.getdata(_self.formData);
				}
			},

			//获取当前比赛数据
			getdata(formData) {
				console.log(234, formData)
				getGameOverLists(formData).then(res => {
					console.log(123, res)
					this.ld_num = res.count;
					let datalist = res.data;
					if (datalist && datalist.length > 0) {
						datalist.forEach(item =>{
							item.game_start_time = item.game_start_time.replace(/-/g,'/')
						})
						if (this.load_sta) {
							if (datalist && datalist.length < 10) {
								this.load_more1 = '没有更多了';
								this.datalist = this.datalist1.concat(datalist);
							} else {
								this.load_more1 = '加载中...';
									this.datalist = this.datalist1.concat(datalist);
							}
						} else {
							if (datalist && datalist.length < 10) {
								this.load_more1 = '没有更多了';
								this.datalist = datalist;
							} else {
								this.load_more1 = '加载中...';
									this.datalist = datalist;
							}
						}
					}
				})
			},
			//跳转比赛详情
			todetail(id) {
				uni.navigateTo({
					url: `/pages/user/entryRecordDetail?id=${id}`
				})
			},
		},
		onPullDownRefresh() {
			console.log('refresh');
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
		}
	}
</script>

<style lang="scss">
	.page-content {
		display: flex;
		height: 100vh;
		width: 100vw;
	}

	.det-con-more {
		display: flex;
		justify-content: center;
		align-items: center;
		margin-bottom: 10rpx;
		color: #bbb;
		font-size: 24rpx;
	}

	.index-header {
		display: flex;
		flex-direction: column;
		width: 100%;
		height: 70rpx;
		background-color: #f5f5f5;
		position: relative;

	}

	.page-body {
		height: 100%;
		padding-top: 30rpx;
		background-color: #f5f5f5;

		.record_li {
			background: #FFFFFF;
			border-radius: 10rpx;
			margin: 0 30rpx 30rpx 30rpx;
			font-size: 28rpx;
			font-weight: bold;
			color: #333333;
			padding-bottom: 10rpx;
			.record_top{
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				padding: 20rpx 30rpx;
				border-bottom: 2rpx solid #f5f5f5;
				font-size: 32rpx;
				font-weight: bold;
				color: #333333;
				.icon-gd{
					color: #999;
				}
			}
			.record_txt{
				padding: 10rpx 30rpx;
				.record_text{
					color: #FE5050;
				}
			}
		}
	}
</style>
